package com.jacken.mars.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jacken.mars.commons.annotation.BaseAnnotationNote;
import com.jacken.mars.entity.base.BasePageRequest;
import com.jacken.mars.entity.base.PageInfo;
import com.jacken.mars.entity.req.SysUserReq;
import com.jacken.mars.entity.resp.R;
import lombok.AllArgsConstructor;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;

import com.jacken.mars.entity.SysUser;
import com.jacken.mars.service.SysUserService;

import javax.annotation.Resource;

/**
 * 控制层
 *
 * @Author wq
 * @Date 2020-12-15
 **/
@RestController
@RequestMapping("admin/sysUser")
@AllArgsConstructor
public class SysUserController {


    private final SysUserService sysUserService;


    /**
     * 新增
     *
     * @param sysUser sysUser
     */
    @PostMapping("/add")
    @BaseAnnotationNote
    public R add(@RequestBody SysUserReq sysUser) {
        sysUserService.add(sysUser);
        return R.success("添加成功");
    }

    /**
     * 删除
     *
     * @param id ids
     */
    @GetMapping("/delete")
    @BaseAnnotationNote
    public R delete(@RequestParam("id") Integer id) {
        sysUserService.delete(id);
        return R.success("删除成功");
    }

    /**
     * 更新
     *
     * @param req sysUser
     */
    @PostMapping("/update")
    @BaseAnnotationNote
    public R update(@RequestBody SysUserReq req) {
        sysUserService.updateSysUser(req);
        return R.success("修改成功");
    }

    /**
     * 详情
     *
     * @param id id
     * @return SysUser
     */
    @GetMapping("/detail")
    @BaseAnnotationNote
    public R detail(@RequestParam("id") Integer id) {
        return R.success(sysUserService.detail(id));
    }

    /**
     * 列表分页
     *
     * @param req query
     * @return IPage<SysUser>
     */
    @PostMapping("/list")
    @BaseAnnotationNote
    public R userList(@RequestBody SysUserReq req) {
        return R.success(sysUserService.sysUserPage(req));
    }

}